<%@page import="org.jbit.news.dao.impl.TopicsDaoImpl"%>
<%@page import="org.jbit.news.entity.Topic"%>
<%@page import="org.jbit.news.entity.News"%>
<%@page import="org.jbit.news.dao.impl.NewsDaoImpl"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'changeNews.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%
  	int id=Integer.valueOf(request.getParameter("id"));
  	NewsDaoImpl nd=new NewsDaoImpl();
  	TopicsDaoImpl td=new TopicsDaoImpl();
  	List<Topic> topics=td.getAllTopics();
  	News news = new News();
  	news=nd.getById(id);
  	session.setAttribute("news",news);
  %>
    <form action="change" method="post">
    <label> 主题： </label>
    <select name="ntid">
	    <%
	    	for(Topic topic: topics){
	        	if(news.getNtid()==topic.getTid()){%>
	        	    <option value='<%= topic.getTid()%>' selected="selected"><%= topic.getTname()%></option>
	        	<%}else{%>
	        	    <option value='<%= topic.getTid()%>' ><%= topic.getTname()%></option>
	        	<%}
	        } 
	    %>
    </select>
      <p>
        <label> 标题： </label>
        <input name="ntitle" type="text" class="opt_input" value="<%=news.getNtitle() %>" />
      </p>
      <p>
        <label> 作者： </label>
        <input name="nauthor" type="text" class="opt_input" value="<%=news.getNauthor() %>" />
      </p>
      <p>
        <label> 摘要：</label>
        <textarea name="nsummary" cols="40" rows="3" ><%=news.getNsummary() %></textarea>
      </p>
      <p>
        <label> 内容：</label>
        <textarea name="ncontent" cols="70" rows="10" ><%=news.getNcontent() %></textarea>
      </p>
      <input name="action" type="hidden" value="addnews"/>
      <input type="submit" value="提交" class="opt_sub" />
      <input type="reset" value="重置" class="opt_sub" />
    </form>
  </body>
</html>
